package com.dshore.messagecenter.dao.overview;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.jdbc.core.BeanPropertyRowMapper;
import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.jdbc.core.RowMapper;
import org.springframework.stereotype.Repository;

import com.dshore.messagecenter.model.system.McColumnInfo;
import com.dshore.messagecenter.model.system.User;

@Repository
public class IndexDao {
	@Autowired
	JdbcTemplate jdbcTemplate;
	
	/**
	 * 获取一级菜单列表
	 * @return
	 */
	public List<McColumnInfo> getFirstColumnInfo(){
		String sql = "select * from T_SYS_MENU where del_flag=0 and pid=-1 order by T_SYS_MENU.id asc";
		RowMapper<McColumnInfo> columnRowMapper = new BeanPropertyRowMapper<>(McColumnInfo.class);
		return  jdbcTemplate.query(sql, columnRowMapper);
	}
	/**
	 * 获取二级菜单列表 主题队列管理
	 * @return
	 */
	public List<McColumnInfo>getSecondColumnInfo1(){
		String sql="select * from T_SYS_MENU where del_flag=0 and pid=2 order by T_SYS_MENU.id asc";
		RowMapper<McColumnInfo> columnRowMapper = new BeanPropertyRowMapper<>(McColumnInfo.class);
		return  jdbcTemplate.query(sql, columnRowMapper);
	}
	/**
	 * 获取二级菜单列表 基础数据
	 * @return
	 */
	public List<McColumnInfo>getSecondColumnInfo2(){
		String sql="select * from T_SYS_MENU where del_flag=0 and pid=3 order by T_SYS_MENU.id asc";
		RowMapper<McColumnInfo> columnRowMapper = new BeanPropertyRowMapper<>(McColumnInfo.class);
		return  jdbcTemplate.query(sql, columnRowMapper);
	}
	/**
	 * 获取二级菜单列表 监控预警
	 * @return
	 */
	public List<McColumnInfo>getSecondColumnInfo3(){
		String sql="select * from T_SYS_MENU where del_flag=0 and pid=4 order by T_SYS_MENU.id asc";
		RowMapper<McColumnInfo> columnRowMapper = new BeanPropertyRowMapper<>(McColumnInfo.class);
		return  jdbcTemplate.query(sql, columnRowMapper);
	}
	/**
	 * 获取二级菜单列表 统计分析
	 * @return
	 */
	public List<McColumnInfo>getSecondColumnInfo4(){
		String sql="select * from T_SYS_MENU where del_flag=0 and pid=5 order by T_SYS_MENU.id asc";
		RowMapper<McColumnInfo> columnRowMapper = new BeanPropertyRowMapper<>(McColumnInfo.class);
		return  jdbcTemplate.query(sql, columnRowMapper);
	}
	/**
	 * 获取二级菜单列表 系统管理
	 * @return
	 */
	public List<McColumnInfo>getSecondColumnInfo5(){
		String sql="select * from T_SYS_MENU where del_flag=0 and pid=6 order by T_SYS_MENU.id asc";
		RowMapper<McColumnInfo> columnRowMapper = new BeanPropertyRowMapper<>(McColumnInfo.class);
		return  jdbcTemplate.query(sql, columnRowMapper);
	}
	/**
	 * 获取二级菜单列表 技术验证
	 * @return
	 */
	public List<McColumnInfo>getSecondColumnInfo6(){
		String sql="select * from T_SYS_MENU where del_flag=0 and pid=7 order by T_SYS_MENU.id asc";
		RowMapper<McColumnInfo> columnRowMapper = new BeanPropertyRowMapper<>(McColumnInfo.class);
		return  jdbcTemplate.query(sql, columnRowMapper);
	}
	
	
	public List<User>getUser(){
		String sql="select T_SYS_USER.id,T_SYS_USER.username from T_SYS_USER where del_flag=0  order by T_SYS_USER.id asc";
		RowMapper<User> columnRowMapper = new BeanPropertyRowMapper<>(User.class);
		return  jdbcTemplate.query(sql, columnRowMapper);
	}
	
	//查询所有菜单
	public List<McColumnInfo> queryAllMenu(){
		String sql = "select * from T_SYS_MENU where del_flag=0 order by T_SYS_MENU.id asc";
		RowMapper<McColumnInfo> columnRowMapper = new BeanPropertyRowMapper<>(McColumnInfo.class);
		return  jdbcTemplate.query(sql, columnRowMapper);
	}
	
	//查询所有pid
	public List<McColumnInfo> queryAllPid(){
		String sql = "SELECT pid FROM T_SYS_MENU group by pid order by pid asc";
		RowMapper<McColumnInfo> columnRowMapper = new BeanPropertyRowMapper<>(McColumnInfo.class);
		return  jdbcTemplate.query(sql, columnRowMapper);
	}
	
	//根据pid查询旗下的所有菜单
	public List<McColumnInfo> getMenuByPid(Integer pid){
		String sql = "select * from T_SYS_MENU where pid=? order by T_SYS_MENU.ORDER_NUM asc";
		RowMapper<McColumnInfo> columnRowMapper = new BeanPropertyRowMapper<>(McColumnInfo.class);
		return  jdbcTemplate.query(sql, columnRowMapper,pid);
	}
}
